#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
void handleSignal(int sigNum)
{
    printf("hello world\n");
    alarm(5);
}

int main(int argc, char const *argv[])
{
    /*注册信号*/
    // signal(SIGINT, handleSignal);
    // signal(SIGQUIT, handleSignal);
    // signal(SIGTSTP, handleSignal);

    // signal(SIGINT, SIG_IGN);

#if 0
    int a = 100;
    int b = 0;

    int c = a/ b;
    printf("c = %d\n",c);
#endif

#if 0
char *ptr = NULL;
printf("%c\n",ptr);
#endif

#if 0
    /*创建管道*/
    int pipeFd[2] = {0};
    pipe(pipeFd);

    /*关闭管道读端*/
    close(pipeFd[0]);

    /*像写端写数据*/
    write(pipeFd[1],"111",strlen("111"));

#endif

    // int cnt = 300;
    // while (cnt--)
    // {
    //     sleep(1);
    // }
    // return 0;

    // abort();
    signal(SIGALRM,handleSignal);
    alarm(5);

#if 0
    pid_t pid = fork();
    if (pid < 0)
    {
        perror("pif error");
        _exit(-1);
    }
    else if (pid == 0)
    {
        signal(SIGINT, handleSignal);
        int cnt = 100;
        while (cnt--)
        {
            sleep(1);
        }
    }
    else
    {
        int cnt = 200;
        while (cnt--)
        {
            sleep(5);
            kill(pid, SIGINT);
        }
    }
#endif

    int cnt = 100;
    while (cnt--)
    {
        sleep(1);
    }
    return 0;
}
